package com.doitedu;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

/**
 * @Date 2021/12/10
 * @Created by HANGGE
 * @Description
 * 获取连接成功以后 指定监听器的process方法
 */
public class C06_Watcher01 {
    public static void main(String[] args) throws  Exception{
        /**
         * 获取ZK的连接
         * 参数三  监听器    监听获取连接成功
         */
        ZooKeeper zk = new ZooKeeper(
                "linux01:2181,linux02:2181,linux03:2181",
                2000,
                new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("连接ZK成功");
            }
        });

        zk.close();

    }
}
